package org.example.mapreduce.count;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.example.mapreduce.FlowWritable;

import java.io.IOException;

/**
 * @author zhl
 * @version 1.0
 * @ClassName
 * @date 2020/11/12 19:20
 */
public class FlowCountCombiner extends Reducer<Text, FlowWritable,Text, FlowWritable> {
    @Override
    protected void reduce(Text key, Iterable<FlowWritable> values, Context context) throws IOException, InterruptedException {
        long up = 0;
        long down = 0;
        for (FlowWritable flowWritable : values) {
            up += flowWritable.getUp().get();
            down += flowWritable.getDown().get();
        }
        context.write(new Text(key.toString()), new FlowWritable(key.toString(), up, down));
    }
}
